/**
 * 描述：使用数组来进行队列的模拟
 *
 * @author WangB
 * @create 2018-10-20-0:26
 */
public class ArrayQueue<E> implements Queue<E> {

    private Array<E> array;

    public ArrayQueue(int capacity){
        array = new Array<>(capacity);
    }

    public ArrayQueue(){
        array = new Array<>();
    }

    public int getCapacity(){
        return array.getCapacity();
    }
    @Override
    public int getSize(){
        return array.getSize();
    }//获取队列的大小
    @Override
    public boolean isEmpty(){
        return array.isEmpty();
    }//是否是空的

    @Override
    public void enqueue(E e){

        array.addLast(e);

    }


    @Override
    public E dequeue(){
        return array.removeFirst();
    }//出队
    @Override
    public E getFront(){
        return array.getFirst();
    }//获取队首元素

    @Override
    public String toString(){
        StringBuilder ret = new StringBuilder();
        ret.append("Queue:");
        ret.append("front[");
        for (int i = 0; i <array.getSize(); i++) {
            ret.append(array.get(i));
            if(i != array.getSize() - 1 )
                ret.append(',');
        }
        ret.append("] tail");
        return ret.toString();

    }

    public static void main(String[] args)
    {
        ArrayQueue<Integer> queue = new ArrayQueue<>();
        for (int i = 0; i < 10; i++) {
            queue.enqueue(i);
            System.out.println(queue);

            if(i % 3 == 2){

                queue.dequeue();
                System.out.println(queue);
            }

        }


    }
}
